package features;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class StreamFeature {

    public void forEach(List<String> list) {
        list.stream().forEach(System.out::println);
    }

    public List<String> filter(List<String> list) {
        return list.stream().filter(s -> s.contains("f")).collect(Collectors.toList());
    }

    public long map(List<String> list) {
        return list.stream().mapToInt(s -> s.length()).count();
    }

    public List<String> sort(List<String> list) {
        // (e1, e2) -> e1.compareTo(e2)
        return list.stream().sorted(String::compareTo).collect(Collectors.toList());
    }

    public List<String> sortReverse(List<String> list) {
        // (e1, e2) -> e2.compareTo(e1)
        return list.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    }

}
